﻿using AutoMapper;
using Common.Utility;
using DTO;
using DTO.DTO.Com.BasicType;
using DTO.DTO.Draw.Draw;
using Interface.TencentCloud;
using Interface.Volcengine;
using Interface.WanX;
using IServices.Com;
using IServices.Draw;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Services.Com;
using Web.Controllers;
using Web.Filter;

namespace Web.Areas.Draw.Controllers
{
    public class DrawController : BaseController
    {
        private readonly IHttpClientFactory _httpClientFactory;
        private readonly VolcengineApi _volcengineApi;
        private readonly TencentCloudApi _tencentCloudApi;
        private readonly WanXApi _wanXApi;
        private readonly IBasicTypeService _basicTypeService;
        public DrawController(IHttpContextAccessor httpContextAccessor, IMapper mapper, IHttpClientFactory httpClientFactory, IBasicTypeService basicTypeService,
            VolcengineApi volcengineApi, TencentCloudApi tencentCloudApi, WanXApi wanXApi)
            : base(httpContextAccessor, mapper)
        {
            _httpClientFactory = httpClientFactory;
            _basicTypeService = basicTypeService;
            _volcengineApi = volcengineApi;
            _tencentCloudApi = tencentCloudApi;
            _wanXApi = wanXApi;
        }
        // GET: Bus/Draw
        public async Task<IActionResult> Index()
        {
            ViewBag.Types = await _basicTypeService.GetList(new BasicTypeQueryDTO { Type = "EntryType" });
            return View();
        }

        public async Task<Result> VolcengineDraw(DrawDTO dto)
        {
            var response = await _volcengineApi.CVProcessAsync(dto.Prompt);

            return Result.Success("成功", response);
        }

        public async Task<Result> TencentCloudDraw(DrawDTO dto)
        {
            var response = await _tencentCloudApi.TextToImageLite(dto.Prompt);

            return Result.Success("成功", response);
        }

        public async Task<Result> WanXDraw(DrawDTO dto)
        {
            var response = await _wanXApi.TurboAsync(dto.Prompt);

            return Result.Success("成功", response);
        }
    }
}